﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using System.Configuration;

namespace Itop.KSRY {
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm {
        UCksmanManager ucksmanMaganer1;
        UCksmanKS3 ucksmanKS1;
        public frmMain() {
            InitializeComponent();
            InitSkins();
            btExam.ItemClick += new ItemClickEventHandler(btExam_ItemClick);
            btImport.ItemClick += new ItemClickEventHandler(btImport_ItemClick);
            btSetup.ItemClick += new ItemClickEventHandler(btSetup_ItemClick);
            btQurey.ItemClick += new ItemClickEventHandler(btQurey_ItemClick);
            btDelete.ItemClick += new ItemClickEventHandler(btDelete_ItemClick);
            WindowState = FormWindowState.Maximized;
            this.Text = About.AssemblyProduct;
        }
        protected override void OnShown(EventArgs e) {
            base.OnShown(e);
            
        }
        void btQurey_ItemClick(object sender, ItemClickEventArgs e) {
            if (ucksmanMaganer1 == null) {
                ucksmanMaganer1 = new UCksmanManager();
                ucksmanMaganer1.Dock = DockStyle.Fill;
                ucksmanMaganer1.Parent = clientPanel;
                ucksmanMaganer1.Init();
            } else {
                ucksmanMaganer1.Show();
                ucksmanMaganer1.Init();
                //ucksmanMaganer1.BringToFront();
            }
            if (ucksmanKS1!=null && ucksmanKS1.Visible) ucksmanKS1.Hide();
        }

        void btSetup_ItemClick(object sender, ItemClickEventArgs e) {
            frmsysset dlg = new frmsysset();
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);
        }
        void btDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("删除后数据不可恢复，确定要删除吗？", "请确认！", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                if (MessageBox.Show("确定要删除人员数据吗？", "请确认?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    DBHelper.Clearksman();
                }
            }
           
        }
        void btImport_ItemClick(object sender, ItemClickEventArgs e) {
            DBHelper.ImportExcel();
        }

        void btExam_ItemClick(object sender, ItemClickEventArgs e) {
            if (ucksmanKS1 == null) {
                ucksmanKS1 = new UCksmanKS3();
                ucksmanKS1.Dock = DockStyle.Fill;
                ucksmanKS1.Parent = clientPanel;
            } else {
                
                //ucksmanKS1.BringToFront();
            }
            ucksmanKS1.Show();
            ucksmanKS1.exam1();
             if (ucksmanMaganer1!=null && ucksmanMaganer1.Visible) ucksmanMaganer1.Hide();
       }
        #region Skins
        string skinMask = "Office 2010";
        BarSubItem iPaintStyle;
        void InitSkins() {
            iPaintStyle = barSubItem1;
            iPaintStyle.Caption = DevExpress.LookAndFeel.UserLookAndFeel.Default.ActiveSkinName;
            foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins) {
                BarButtonItem item = new BarButtonItem();
                item.Caption = cnt.SkinName;
                ribbon.Items.Add(item);
                iPaintStyle.ItemLinks.Add(item);
                item.ItemClick += new ItemClickEventHandler(OnSkinClick);
            }
        }
        void OnSkinClick(object sender, ItemClickEventArgs e) {
            string skinName = e.Item.Caption;
            Properties.Settings.Default.skinName = skinName;
            Properties.Settings.Default.Save();
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skinName);
            iPaintStyle.Caption = e.Item.Caption;
            iPaintStyle.Hint = iPaintStyle.Caption;
        }
        #endregion
    }
}